package com.ptadmin.report.mws.sample;

import com.amazonaws.mws.MarketplaceWebService;
import com.amazonaws.mws.MarketplaceWebServiceClient;
import com.amazonaws.mws.MarketplaceWebServiceConfig;
import com.amazonaws.mws.MarketplaceWebServiceException;
import com.amazonaws.mws.model.GetReportRequestListRequest;
import com.amazonaws.mws.model.GetReportRequestListResponse;
import com.amazonaws.mws.model.GetReportRequestListResult;
import com.amazonaws.mws.model.ReportRequestInfo;
import com.amazonaws.mws.model.ResponseMetadata;

public class GetReportRequestList {
	public static void main(String[] args) {
		/************************************************************************
		 * Access Key ID and Secret Access Key ID, obtained from: http://aws.amazon.com
		 ***********************************************************************/
		final String accessKeyId = "AKIAI2JEZAYVZZZ3GHGA";
		final String secretAccessKey = "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";

		final String appName = "ptadmin";
		final String appVersion = "1.0.0";
		
		MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();

		config.setServiceURL("https://mws.amazonservices.com/");

		MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, appName,
				appVersion, config);

		final String merchantId = "A2N95VZZXMVRLW";
		final String sellerDevAuthToken = "amzn.mws.52b2d181-1d65-65a8-04f7-e12ce26cfad5";

		GetReportRequestListRequest request = new GetReportRequestListRequest();
		request.setMerchant(merchantId);
		request.setMWSAuthToken(sellerDevAuthToken);

		// @TODO: set request parameters here

		invokeGetReportRequestList(service, request);
	}

	/**
	 * Get Report Request List request sample returns a list of report requests ids
	 * and their associated metadata
	 * 
	 * @param service
	 *            instance of MarketplaceWebService service
	 * @param request
	 *            Action to invoke
	 */
	public static void invokeGetReportRequestList(MarketplaceWebService service, GetReportRequestListRequest request) {
		try {

			GetReportRequestListResponse response = service.getReportRequestList(request);

			System.out.println("GetReportRequestList Action Response");
			System.out.println("=============================================================================");
			System.out.println();

			System.out.print("    GetReportRequestListResponse");
			System.out.println();
			if (response.isSetGetReportRequestListResult()) {
				System.out.print("        GetReportRequestListResult");
				System.out.println();
				GetReportRequestListResult getReportRequestListResult = response.getGetReportRequestListResult();
				if (getReportRequestListResult.isSetNextToken()) {
					System.out.print("            NextToken");
					System.out.println();
					System.out.print("                " + getReportRequestListResult.getNextToken());
					System.out.println();
				}
				if (getReportRequestListResult.isSetHasNext()) {
					System.out.print("            HasNext");
					System.out.println();
					System.out.print("                " + getReportRequestListResult.isHasNext());
					System.out.println();
				}
				java.util.List<ReportRequestInfo> reportRequestInfoList = getReportRequestListResult
						.getReportRequestInfoList();
				for (ReportRequestInfo reportRequestInfo : reportRequestInfoList) {
					System.out.print("            ReportRequestInfo");
					System.out.println();
					if (reportRequestInfo.isSetReportRequestId()) {
						System.out.print("                ReportRequestId");
						System.out.println();
						System.out.print("                    " + reportRequestInfo.getReportRequestId());
						System.out.println();
					}
					if (reportRequestInfo.isSetReportType()) {
						System.out.print("                ReportType");
						System.out.println();
						System.out.print("                    " + reportRequestInfo.getReportType());
						System.out.println();
					}
					if (reportRequestInfo.isSetStartDate()) {
						System.out.print("                StartDate");
						System.out.println();
						System.out.print("                    " + reportRequestInfo.getStartDate());
						System.out.println();
					}
					if (reportRequestInfo.isSetEndDate()) {
						System.out.print("                EndDate");
						System.out.println();
						System.out.print("                    " + reportRequestInfo.getEndDate());
						System.out.println();
					}
					if (reportRequestInfo.isSetSubmittedDate()) {
						System.out.print("                SubmittedDate");
						System.out.println();
						System.out.print("                    " + reportRequestInfo.getSubmittedDate());
						System.out.println();
					}
					if (reportRequestInfo.isSetCompletedDate()) {
						System.out.print("                CompletedDate");
						System.out.println();
						System.out.print("                    " + reportRequestInfo.getCompletedDate());
						System.out.println();
					}
					if (reportRequestInfo.isSetReportProcessingStatus()) {
						System.out.print("                ReportProcessingStatus");
						System.out.println();
						System.out.print("                    " + reportRequestInfo.getReportProcessingStatus());
						System.out.println();
					}
				}
			}
			if (response.isSetResponseMetadata()) {
				System.out.print("        ResponseMetadata");
				System.out.println();
				ResponseMetadata responseMetadata = response.getResponseMetadata();
				if (responseMetadata.isSetRequestId()) {
					System.out.print("            RequestId");
					System.out.println();
					System.out.print("                " + responseMetadata.getRequestId());
					System.out.println();
				}
			}
			System.out.println();
			System.out.println(response.getResponseHeaderMetadata());
			System.out.println();

		} catch (MarketplaceWebServiceException ex) {

			System.out.println("Caught Exception: " + ex.getMessage());
			System.out.println("Response Status Code: " + ex.getStatusCode());
			System.out.println("Error Code: " + ex.getErrorCode());
			System.out.println("Error Type: " + ex.getErrorType());
			System.out.println("Request ID: " + ex.getRequestId());
			System.out.print("XML: " + ex.getXML());
			System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
		}
	}
}
